package cn.stylefeng.guns.modular.robot.cmd.impl;

import cn.stylefeng.guns.modular.robot.cmd.Cmd;
import cn.stylefeng.guns.modular.robot.cmd.abs.AbstractCmd;
import cn.stylefeng.guns.modular.robot.utils.RobotUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.api.objects.Update;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
@Transactional
public class CmdHelp extends AbstractCmd {

    @Resource
    private List<Cmd> cmds;

    @Override
    public void exec(Update update, TelegramLongPollingBot bot) {
        String text = update.getMessage().getText();
        if (!getCmdName().equals(text)) {
            return;
        }
        StringBuilder sb = new StringBuilder();
        sb.append(getDescribe());
        for (Cmd cmd : cmds) {
            if (StringUtils.isBlank(cmd.getDescribe())) {
                continue;
            }
            sb.append(cmd.getDescribe());
        }
        RobotUtils.sendText(update.getMessage().getChatId(), sb.toString(), bot);
    }

    @Override
    public String getCmdName() {
        return "指令查询";
    }

    @Override
    public String getDescribe() {
        return "指令查询                   查看群所有指令\n";
    }
}
